import java.util.Arrays;
import java.util.List;
import java.util.Stack;

public class Solution636 {
    public int[] exclusiveTime(int n, List<String> logs) {
        int[] f=new int[n];
        Stack<int[]> stack=new Stack<>();
        for (String log : logs) {
            String[] strings=log.split(":");
            if (strings[1].equals("start")){
                if (!stack.isEmpty()){
                    int[] temp=stack.peek();
                    int time=Integer.parseInt(strings[2])-temp[1];
                    f[temp[0]]=f[temp[0]]+time;
                }
                stack.push(new int[]{Integer.parseInt(strings[0]),Integer.parseInt(strings[2])});
            }else{
                int[] temp=stack.pop();
                int time=Integer.parseInt(strings[2])-temp[1]+1;
                f[temp[0]]=f[temp[0]]+time;
                if (!stack.isEmpty()){
                    stack.peek()[1]=Integer.parseInt(strings[2])+1;
                }
            }
        }
        return f;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution636().exclusiveTime(2, Arrays.asList("0:start:0", "1:start:2", "1:end:5", "0:end:6"))));
    }
}
